using System;
using UnityEngine;

public class tk2dUISound : tk2dUIBaseItemControl
{
	private void OnEnable()
	{
		if (this.uiItem == null)
		{
			return;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[0]))
		{
			this.uiItem.OnDown += this.PlayDownSound;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[1]))
		{
			this.uiItem.OnUp += this.PlayUpSound;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[2]))
		{
			this.uiItem.OnClick += this.PlayClickSound;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[3]))
		{
			this.uiItem.OnRelease += this.PlayReleaseSound;
		}
	}

	private void OnDisable()
	{
		if (this.uiItem == null)
		{
			return;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[0]))
		{
			this.uiItem.OnDown -= this.PlayDownSound;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[1]))
		{
			this.uiItem.OnUp -= this.PlayUpSound;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[2]))
		{
			this.uiItem.OnClick -= this.PlayClickSound;
		}
		if (!string.IsNullOrEmpty(this.buttonSounds[3]))
		{
			this.uiItem.OnRelease -= this.PlayReleaseSound;
		}
	}

	private void PlayDownSound()
	{
		this.PlaySound(this.buttonSounds[0]);
	}

	private void PlayUpSound()
	{
		this.PlaySound(this.buttonSounds[1]);
	}

	private void PlayClickSound()
	{
		this.PlaySound(this.buttonSounds[2]);
	}

	private void PlayReleaseSound()
	{
		this.PlaySound(this.buttonSounds[3]);
	}

	private void PlaySound(string clipName)
	{
		if (string.IsNullOrEmpty(clipName))
		{
			return;
		}
		BMSoundHelper.Play(clipName, false, 1f);
	}

	[HideInInspector]
	[SerializeField]
	public string[] buttonSounds = new string[4];
}
